

import { baseUrl, khglUrl, dicUrl } from '@/config/env'
import request from '@/router/axios'
import { userInfo, tableData } from '@/mock/user'
import { menu, menuAll } from '@/mock/menu'
export const loginByUsername = (username, password, code, randomStr) => {
  var grant_type = 'password'
  var scope = 'server'
  return request({
    url: baseUrl + '/ceo-oauth2/oauth/token',
    headers: {
      'Authorization': 'Basic c2VydmljZTphYmMxMjM=',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: 'post',
    params: { username, password, randomStr, code, grant_type, scope }
  })
}

export function mobileLogin(mobile, code) {
  var grant_type = 'mobile'
  var scope = 'server'
  return request({
    url: baseUrl + '/ceo-oauth2/mobile/token',
    headers: {
      'Authorization': 'Basic c2VydmljZTphYmMxMjM='
    },
    method: 'post',
    params: { mobile, code, grant_type, scope }
  })
}

export const getUserInfo = () => {
  return request({
    url: baseUrl + '/ceo-user/user/info',
    method: 'get'
  })
}

export const getUserPermissions = (userId) => {
  return request({
    url: baseUrl + '/ceo-user/permission/get/' + userId,
    method: 'get'
  })
}

export const logout = (accesstoken, refreshToken) => {
  return request({
    url: baseUrl + '/ceo-oauth2/authentication/removeToken',
    method: 'post',
    params: { accesstoken, refreshToken }
  })
}
